{% extends 'TopxiaWebBundle::layout.html.twig' %}

{% block title %}登录 - {{ parent() }}{% endblock %}
{% set script_controller = 'auth/login' %}
{% block content %}
{% if app.request.cookies.get('modalOpened') == 1 %}
  <a href="#modal" class=" hidden" data-toggle="modal" data-url="{{ path('card_info',{'cardType':app.request.query.get('cardType'),'cardId':app.request.query.get('cardId')}) }}" class="hidden" ><span class="receive-modal"></span></a>
{% endif %}
<div class="es-section login-section">
  <div class="logon-tab clearfix">
    <a class="active">登录帐号</a>
    <a href="{{ path('register', {goto:_target_path}) }}">注册帐号</a>
  </div>
  <div class="login-main">
    <form id="login-form" class="form-vertical" method="post" action="{{ path('login_check') }}">

      {% if error %}
        <div class="alert alert-danger">{{ error.message|trans }}</div>
      {% endif %}
      {{ web_macro.flash_messages() }}
      <div class="form-group mbl">
        <label class="control-label" for="login_username">帐号</label>
        <div class="controls">
          <input class="form-control input-lg" id="login_username" type="text" name="_username" value="{{ last_username }}" required placeholder='邮箱/手机/用户名' />
          <div class="help-block"></div>
        </div>
      </div>
      <div class="form-group mbl">
        <label class="control-label" for="login_password">密码</label>
        <div class="controls">
          <input class="form-control input-lg" id="login_password" type="password" name="_password" required placeholder='密码'/>
        </div>
      </div>

      <div class="form-group mbl">
        <div class="controls">
          <input type="checkbox" name="_remember_me" checked="checked"> 记住密码
        </div>
      </div>
      <div class="form-group mbl">
        <button type="submit" class="btn btn-primary btn-lg btn-block">登录</button>
      </div>

      <input type="hidden" name="_target_path" value="{{ _target_path }}">
      <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
    </form>

    <div class="mbl">
      <a href="{{ path('password_reset') }}">找回密码</a>
      <span class="text-muted mhs">|</span>
      <span class="text-muted">还没有注册帐号？</span>
      <a href="{{ path('register', {goto:_target_path}) }}">立即注册</a>
    </div>
<p style="text-align:center;color:#e83248">通过以下帐号快捷登录</p>
    {% if setting('login_bind.enabled') %}
      <div class="social-login">
        <span>
          {{ render(controller('TopxiaWebBundle:Login:oauth2LoginsBlock', {targetPath:_target_path})) }}
        </span>
        <div class="line"></div>
      </div>
    {% endif %}
  </div>
</div>
<!-- <script src="{#{ cdnUrl }#}{{ asset('assets/libs/base64.js') }}"></script> -->
<script src="{{ asset('assets/libs/base64.js') }}"></script>
<script type="text/javascript">
  //add by lgw
  //写cookies
  function setCookie(name,value)
  {
      var Days = 30;
      var exp = new Date();
      exp.setTime(exp.getTime() + Days*24*60*60*1000);
      document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  }
  function getCookie(name)
  {
      var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
      if(arr=document.cookie.match(reg))
          return unescape(arr[2]);
      else
          return null;
  }


  /**
   *
   * 解决登陆页面加载出来的时候显示"$ is not defined"的错误,把submit函数放到
   * E:\newwangxiao\web\bundles\topxiaweb\js\controller\auth\login.js  这个文件中
  **/
  /*
  $("#login-form").submit(function () {
      var username = $("#login_username").val();
      var password = $("#login_password").val();
      var urlpar = "username="+username+"&password="+password;
      setCookie("logincookie",base64encode(urlpar));
  });
*/
  //网校这边登录需要做的操作
  //1、如果是用户名和密码登录，将用户名和密码加密存储在cookie
  //2、如果用第三方登录，需要将用户名和密码从数据库中查询出来加密后存储到cookie中
  //3、如果数据库中查询出的密码如果加密了，需要解密才可以
  //4、在需要跳转到OM课堂登录界面的地方，用OM联系+？加密后的用户名和密码
</script>
{% endblock %}